# coding:utf-8
import os

from config import upload_video_url
from utils.range import Range


def getTokenedFile(token):
    print(token)
    file_path = upload_video_url
    if not os.path.exists(file_path):
        os.makedirs(file_path)
    file = open(file_path + "/" + token, 'w')
    return file


def parseRange(req):
    range = req.headers['content-range']
    range = range.replace('bytes ', '')
    rangeSize = range.split("/");
    fromTo = rangeSize[0].split("-");
    frm = int(fromTo[0])
    to = int(fromTo[1])
    size = int(rangeSize[1])
    return Range(frm, to, size)


if __name__ == '__main__':
    # file = getTokenedFile('bbb.txt')
    # file.write('aaaaaaaaa')
    print(os.path.getsize(upload_video_url + '/' + 'bbb.txt'))
